package cn.edu.scau.cmi.guihao.pane;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.guihao.classAdapter.MicroToTypeC;
import cn.edu.scau.cmi.guihao.classAdapter.TypeCToMicro;
import cn.edu.scau.cmi.guihao.domin.adapter.USBMicro;
import cn.edu.scau.cmi.guihao.domin.adapter.USBTypeC;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Pane;

public class ClassAdapterPane extends Pane implements Initializable {

	@FXML
	private ComboBox<String> phoneInterfaceType;
	@FXML
	private ComboBox<String> chargerInterfaceType;
	@FXML
	private TextArea conTextArea;
	
	public ClassAdapterPane() {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/guihao/view/ClassAdapter.fxml"));
        loader.setRoot(this);
        loader.setController(this);
        try {
            loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		ObservableList<String> type = FXCollections.observableArrayList("micro","type-c");
		phoneInterfaceType.setItems(type);
		chargerInterfaceType.setItems(type);
	}
	
	@FXML
	public void onChargeClick() {
		String context;
		if(phoneInterfaceType.getValue()=="type-c" && chargerInterfaceType.getValue()=="type-c") {
			context = new USBTypeC().useTypeC();
		}else if(phoneInterfaceType.getValue()=="micro" && chargerInterfaceType.getValue()=="type-c") {
			context = new MicroToTypeC().useMicro();
		}else if(phoneInterfaceType.getValue()=="micro" && chargerInterfaceType.getValue()=="micro") {
			context = new USBMicro().useMicro();
		}else if(phoneInterfaceType.getValue()=="type-c" && chargerInterfaceType.getValue()=="micro") {
			context = new TypeCToMicro().useTypeC();
		}else {
			context="error";
		}
		conTextArea.setText(context);
	}

	
}
